//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.service;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.example.entity.Account;
import com.example.entity.Article;
import com.example.exception.CustomException;
import com.example.mapper.ArticleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class ArticleService {
    @Resource
    private ArticleMapper articleMapper;

    public ArticleService() {
    }

    public void add(Article article) { //管理员不需要注册只需要新增，只有管理员才能增加管理员
        article.setTime(DateUtil.now());//获得当前的最新的时间字符串
        this.articleMapper.insert(article);
    }

    public void updateById(Article article) {
        this.articleMapper.updateById(article);
    }

    public void deleteById(Integer id) {
        this.articleMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        Iterator var2 = ids.iterator();

        while(var2.hasNext()) {
            Integer id = (Integer)var2.next();
            this.deleteById(id);
        }

    }

    public Article selectById(Integer id) {
        return this.articleMapper.selectById(id);
    }

    public List<Article> selectAll(Article article) {
        return this.articleMapper.selectAll(article);
    }

    public List<Article> selectList(Article article) {
        System.out.println(article);
        return null;
    }

    public PageInfo<Article> selectPage(Article article, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Article> list = this.articleMapper.selectAll(article);
        return PageInfo.of(list);
    }
    
}
